package com.yf.exam.modules.trainingarchives.evaluation.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.exam.common.entity.Result;
import com.yf.exam.core.api.dto.BaseIdReqDTO;
import com.yf.exam.core.api.dto.PagingReqDTO;
import com.yf.exam.core.exception.ServiceException;
import com.yf.exam.modules.trainingarchives.evaluation.dto.CreateEvaluationDTO;
import com.yf.exam.modules.trainingarchives.evaluation.dto.EvaluationInfoDTO;
import com.yf.exam.modules.trainingarchives.evaluation.service.IEvaluationInfoService;
import com.yf.exam.modules.trainingarchives.evaluation.vo.EvaluationInfoListVO;
import com.yf.exam.modules.trainingarchives.evaluation.vo.EvaluationVO;
import com.yf.exam.modules.trainingarchives.pdfexport.dto.second.EvaluationInfoExportDTO;
import com.yf.exam.modules.trainingarchives.teacherattendance.dto.TeacherAttendanceDTO;
import com.yf.exam.modules.trainingarchives.teacherattendance.vo.TeacherAttendanceListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 满意度调查详情表 前端控制器
 * </p>
 *
 * @author lql
 * @since 2025-01-06
 */
@Api(tags={"满意度调查详情表"})
@RestController
@RequestMapping("/org/api/evaluation-info")
@Slf4j
public class EvaluationInfoController {


    @Resource
    private IEvaluationInfoService  iEvaluationInfoService;
    /**
     * 添加
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "保存满意度调查详情")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody EvaluationInfoDTO reqDTO) {
        try {
            //复制参数
            iEvaluationInfoService.add(reqDTO);
            return Result.ok();
        }catch (ServiceException e){
            return Result.faild(e);
        }
    }

    /**
     * 分页查找
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public Result<IPage<EvaluationInfoListVO>> paging(@RequestBody PagingReqDTO<EvaluationInfoListVO> reqDTO) {
        try {
            if (log.isInfoEnabled()) {
                log.info("EvaluationInfoController.paging.dto:{}", JSON.toJSONString(reqDTO));
            }
            //分页查询并转换
            IPage<EvaluationInfoListVO> page = iEvaluationInfoService.paging(reqDTO);
            return Result.ok(page);
        } catch (Exception e) {
            log.error("TeachingPlanExecutionController.paging.error:{}", e.getMessage(), e);
            return Result.faild("查询失败");
        }
    }

    /**
     * 分页查找
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/getList")
    public Result<List<EvaluationInfoExportDTO>> getList(@RequestBody EvaluationInfoListVO reqDTO) {
        try {
            if (log.isInfoEnabled()) {
                log.info("EvaluationInfoController.paging.dto:{}", JSON.toJSONString(reqDTO));
            }
            Map<String,Object> queryMap = new HashMap<String,Object>();
            queryMap.put("type",reqDTO.getType());
            queryMap.put("trainingClassInfoId",reqDTO.getTrainingClassInfoId());
            //分页查询并转换
            List<EvaluationInfoExportDTO> page = iEvaluationInfoService.getEvaluationInfoExportDTOList(queryMap);
            return Result.ok(page);
        } catch (Exception e) {
            log.error("TeachingPlanExecutionController.paging.error:{}", e.getMessage(), e);
            return Result.faild("查询失败");
        }
    }

    /**
     * 分页查找
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "获取文件详情")
    @PostMapping("/getDetails")
    public Result<EvaluationVO> getDetails(@RequestBody BaseIdReqDTO reqDTO) {
        try {
            if (log.isInfoEnabled()) {
                log.info("EvaluationInfoController.paging.dto:{}", JSON.toJSONString(reqDTO));
            }
            //分页查询并转换
            EvaluationVO evaluationVO = iEvaluationInfoService.getDetails(reqDTO.getId());
            return Result.ok(evaluationVO);
        } catch (Exception e) {
            log.error("TeachingPlanExecutionController.paging.error:{}", e.getMessage(), e);
            return Result.faild("查询失败");
        }
    }


}
